package com.sensePlusVR.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.ScrollView;

import com.sensePlusVR.utils.MyLog;

/**
 * 屏蔽 滑动事件
 */
public class MyScrollview extends ScrollView {
	private static final String TAG = MyScrollview.class.getSimpleName();
	private int downX;
	private int downY;
	private int mTouchSlop;

	public MyScrollview(Context context) {
		super(context);
		mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
	}

	public MyScrollview(Context context, AttributeSet attrs) {
		super(context, attrs);
		mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
	}

	public MyScrollview(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
	}
	
	
	float moveX = 0;
	float moveY = 0;

	@Override
	public boolean onInterceptTouchEvent(MotionEvent e) {
		int action = e.getAction();
		MyLog.d(TAG, "onInterceptTouchEvent action : " + action);
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			downX = (int) e.getX();
			downY = (int) e.getY();
			moveX = 0;
			moveY = 0;
			return super.onInterceptTouchEvent(e);
		case MotionEvent.ACTION_MOVE:
			moveX = Math.abs(e.getX() - downX);// X轴距离
			moveY = Math.abs(e.getY() - downY);// y轴距离
			boolean isYMoved = moveY > mTouchSlop;
			MyLog.d(TAG, "moveY : " + moveY + " moveX : " + moveX
					+ " mTouchSlop : " + mTouchSlop);
			if (isYMoved) {
				if (moveY > moveX) {
					return super.onInterceptTouchEvent(e);
				}
			}
		}
		return false;
	}
}
